/**
 * 
 */
package com.postek.coyote.postekwifi;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


import com.postek.cdf.CDFPTKAndroid;
import com.postek.coyote.postekwifi.bean.LabelBean;
import com.postek.coyote.postekwifi.bean.MessageBean;

import java.util.ArrayList;


/**
 * @author yrwang
 *
 */
public class PrintActivity extends AppCompatActivity{

	private CDFPTKAndroid cdf = MainActivity.cdf;
	private MessageBean messageBean = MainActivity.messageBean;
	private ArrayList<LabelBean> labelBeans = MainActivity.labelBeans;
	
	private Button btn_print = null;
//	private Bitmap bitmap = null;
	
	private EditText et_S = null;
	private EditText et_H = null;
	private EditText et_Z = null;
	private EditText et_q = null;
	private EditText et_Q1 = null;
	private EditText et_Q2 = null;
	private EditText et_Q3 = null;
	private EditText et_Q4 = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.print);
		
		btn_print = (Button) findViewById(R.id.btn_set_over);
		
		et_S = (EditText) findViewById(R.id.et_set_S);
		et_H = (EditText) findViewById(R.id.et_set_H);
		et_Z = (EditText) findViewById(R.id.et_set_Z);
		et_q = (EditText) findViewById(R.id.et_set_q);
		et_Q1 = (EditText) findViewById(R.id.et_set_Q1);
		et_Q2 = (EditText) findViewById(R.id.et_set_Q2);
		et_Q3 = (EditText) findViewById(R.id.et_set_Q3);
		et_Q4 = (EditText) findViewById(R.id.et_set_Q4);
		
		
//		bitmap = BitmapFactory.decodeResource(this.getResources(), this.getResources().getIdentifier("test12", "drawable", this.getApplicationInfo().packageName));
		
		btn_print.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iS = messageBean.getiS();
				if(!("".equals(et_S.getText().toString()))){
					iS = Integer.parseInt(et_S.getText().toString());
					messageBean.setiS(iS);
				}
				
				int iH = messageBean.getiH();
				if(!("".equals(et_H.getText().toString()))){
					iH = Integer.parseInt(et_H.getText().toString());
					messageBean.setiH(iH);
				}
				
				String iZ = messageBean.getiZ();
				if("B".equals(et_Z.getText().toString())){
					iZ = "B";
					messageBean.setiZ(iZ);
				} else {
					iZ = "T";
					messageBean.setiZ(iZ);
				}
				
				int iq = messageBean.getiq();
				if(!("".equals(et_q.getText().toString()))){
					iq = Integer.parseInt(et_q.getText().toString());
					messageBean.setiq(iq);
				}
				
				int iQ1 = messageBean.getiQ1();
				if(!("".equals(et_Q1.getText().toString()))){
					iQ1 = Integer.parseInt(et_Q1.getText().toString());
					messageBean.setiQ1(iQ1);
				}
				
				int iQ2 = messageBean.getiQ2();
				if(!("".equals(et_Q2.getText().toString()))){
					iQ2 = Integer.parseInt(et_Q2.getText().toString());
					messageBean.setiQ2(iQ2);
				}
				
				int iQ3 = messageBean.getiQ3();
				if(!("".equals(et_Q3.getText().toString()))){
					iQ3 = Integer.parseInt(et_Q3.getText().toString());
					messageBean.setiQ3(iQ3);
				}
				
				boolean iQ4 = messageBean.getiQ4();
				if("true".equals(et_Q4.getText().toString())){
					iQ4 = true;
					messageBean.setiQ4(iQ4);
				} else {
					iQ4 = false;
					messageBean.setiQ4(iQ4);
				}
				
				cdf.PTK_ClearBuffer();
				cdf.PTK_SetPrintSpeed(iS);
				cdf.PTK_SetDarkness(iH);
				cdf.PTK_SetDirection(iZ);
				cdf.PTK_SetLabelWidth(iq);
				cdf.PTK_SetLabelHeight(iQ1, iQ2, iQ3, iQ4);

				if (iq!=0 && iQ1!=0 ) {
                    Log.e("TAG", "onClick: "+et_q.getText().toString()+et_Q1.getText().toString()+et_Q2.getText().toString());
                    Intent intent = new Intent();
					intent.setClass(PrintActivity.this, MessageActivity.class);
					PrintActivity.this.startActivity(intent);
					finish();
				}else {
                    Toast.makeText(PrintActivity.this, R.string.Incomplete_info, Toast.LENGTH_LONG).show();
				}
				labelBeans.clear();

			}
		});
	}

}
